package com.inossem.warehousestorage_inossem.request;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.LoginBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by leij on 2017/6/13.
 */

public class LoginRequest extends Request {

    private static final String USER_NAME = "username";//用户名

    private static final String PASSWORD = "password";//密码

    public static String request(Context context, String userName, String password, GsonBeanListener gsonBeanListener) {
        String tag;
        Map<String, String> params = new HashMap<>();
        params.put(USER_NAME, userName);
        params.put(PASSWORD, password);
        String url = RequestManage.getUrl(context, RequestConstant.URL_LOGIN + RequestManage.mapEncodeToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                LoginBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), LoginBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
        return tag;
    }

}
